this.BX=this.BX||{};this.BX.UI=this.BX.UI||{};(function(t,e,i,n,o,s){"use strict";class r{static getV4(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){var e=Math.random()*16|0,i=t=="x"?e:e&3|8;return i.toString(16)}))}}class a{constructor(t){this.setUid(t.id);this.setCategory(t.category);this.setTitle(t.title);this.setText(t.text);this.setIcon(t.icon);this.setInputPlaceholderText(t.inputPlaceholderText);this.createButtons(t.button1Text,t.button2Text)}static encodeIdToUid(t){return t+a.SEPARATOR+r.getV4()}static decodeUidToId(t){let e=t.split(a.SEPARATOR);e.pop();return e.join()}setUid(t){if(!n.Type.isStringFilled(t)){throw new Error(`NotificationManager: Cannot create a notification without an ID`)}this.uid=a.encodeIdToUid(t)}getUid(){return this.uid}getId(){return a.decodeUidToId(this.uid)}setCategory(t){this.category=n.Type.isStringFilled(t)?t:""}getCategory(){return this.category}setTitle(t){this.title=n.Type.isStringFilled(t)?t:""}getTitle(){return this.title}setText(t){this.text=n.Type.isStringFilled(t)?t:""}getText(){return this.text}setIcon(t){this.icon=n.Type.isStringFilled(t)?t:""}getIcon(){return this.icon}setInputPlaceholderText(t){if(n.Type.isString(t)){this.inputPlaceholderText=t}}getInputPlaceholderText(){return this.inputPlaceholderText}createButtons(t,e){if(this.getInputPlaceholderText()){this.setButton1Text(n.Loc.getMessage("UI_NOTIFICATION_MANAGER_REPLY"));this.setButton2Text(n.Loc.getMessage("UI_NOTIFICATION_MANAGER_CLOSE"))}else{this.setButton1Text(t);this.setButton2Text(e)}}setButton1Text(t){if(n.Type.isStringFilled(t)){this.button1Text=t}}getButton1Text(){return this.button1Text}setButton2Text(t){if(n.Type.isStringFilled(t)){this.button2Text=t}}getButton2Text(){return this.button2Text}}a.SEPARATOR="u1F9D1";class c extends a{setUid(t){if(!n.Type.isStringFilled(t)){throw new Error(`NotificationManager: Cannot create a notification without an ID`)}this.uid=t}}class d{getModuleId(){return"ui"}handleNotify(t,e,i){const n=t.notification;if(!n){throw new Error("NotificationManager: Incorrect notification format")}const o=n;const s=new c(o);U.sendNotification(s)}}class u{static isSupportedDesktopApp(){return u.isBitrixDesktop()&&u.geApiVersion()>=67}static isBitrixDesktop(){return navigator.userAgent.toLowerCase().includes("bitrixdesktop")}static geApiVersion(){if(typeof BXDesktopSystem==="undefined"){return 0}return Number(BXDesktopSystem.GetProperty("versionParts")[3])}static isMainTab(){if(typeof BXDesktopSystem==="undefined"){return false}return typeof BX.desktop!=="undefined"&&BX.desktop.apiReady}static isMac(){return navigator.userAgent.toLowerCase().includes("macintosh")}static isLinux(){return navigator.userAgent.toLowerCase().includes("linux")}static isWindows(){return navigator.userAgent.toLowerCase().includes("windows")||!u.isMac()&&!u.isLinux()}static isRunningOnAnyDevice(){return BXIM&&BXIM.desktopStatus}static checkRunningOnThisDevice(){return new Promise((t=>{const e=()=>{t(true)};const i=()=>{t(false)};BX.desktopUtils.runningCheck(e,i)}))}}class l{static isSupportedBrowser(){return l.isChrome()||l.isFirefox()||l.isSafari()}static isNativeNotificationAllowed(){return window.Notification&&window.Notification.permission&&window.Notification.permission.toLowerCase()==="granted"}static isSafari(){if(l.isChrome()){return false}if(!navigator.userAgent.toLowerCase().includes("safari")){return false}return!l.isSafariBased()}static isSafariBased(){if(!navigator.userAgent.toLowerCase().includes("applewebkit")){return false}return navigator.userAgent.toLowerCase().includes("yabrowser")||navigator.userAgent.toLowerCase().includes("yaapp_ios_browser")||navigator.userAgent.toLowerCase().includes("crios")}static isChrome(){return navigator.userAgent.toLowerCase().includes("chrome")}static isFirefox(){return navigator.userAgent.toLowerCase().includes("firefox")}}class g extends i.BaseEvent{static getTypes(){return[g.CLICK,g.ACTION,g.CLOSE]}static isSupported(t){return g.getTypes().includes(t)}}g.CLICK="click";g.ACTION="action";g.CLOSE="close";class p{static getTypes(){return[p.BUTTON_1,p.BUTTON_2,p.USER_INPUT]}static isSupported(t){return p.getTypes().includes(t)}}p.BUTTON_1="button_1";p.BUTTON_2="button_2";p.USER_INPUT="user_input";class f{static getTypes(){return[f.CLOSED_BY_USER,f.EXPIRED]}static isSupported(t){return f.getTypes().includes(t)}}f.CLOSED_BY_USER="closed_by_user";f.EXPIRED="expired";class h extends i.EventEmitter{constructor(t={}){super();if(n.Type.isStringFilled(t.eventNamespace)){this.setEventNamespace(t.eventNamespace)}}convertNotificationToNative(t){throw new Error("convertNotificationToNative() method must be implemented.")}sendNotification(t){throw new Error("sendNotification() method must be implemented.")}canSendNotification(t){return true}notify(t){if(!this.canSendNotification(t)){return}const e=this.convertNotificationToNative(t);this.sendNotification(e)}notificationClick(t=""){const e={data:{id:a.decodeUidToId(t)}};this.emit(g.CLICK,new g(e))}notificationAction(t="",e="",i=null){if(!p.isSupported(e)){console.warn(`NotificationManager: Unknown notification action "${e}".`)}const n={data:{id:a.decodeUidToId(t),action:e}};if(i){n.data.userInput=i}this.emit(g.ACTION,new g(n))}notificationClose(t="",e=""){if(!f.isSupported(e)){console.warn(`NotificationManager: Unknown notification close reason "${e}".`)}const i={data:{id:a.decodeUidToId(t),reason:e}};this.emit(g.CLOSE,new g(i))}}h.NOTIFICATION_LIFETIME=144e5;class T extends h{constructor(t={}){super(t);if(this.getEventNamespace()){this.registerEvents()}}convertNotificationToNative(t){throw new Error("convertNotificationToNative() method must be implemented.")}canSendNotification(t){return u.isMainTab()||!(t instanceof c)}sendNotification(t){BXDesktopSystem.NotificationShow(t)}registerEvents(){window.addEventListener("BXNotificationClick",(t=>this.onNotificationClick(t)));window.addEventListener("BXNotificationAction",(t=>this.onNotificationAction(t)));window.addEventListener("BXNotificationDismissed",(t=>this.onNotificationClose(t)))}onNotificationClick(t){const[e]=t.detail;this.notificationClick(e)}onNotificationAction(t){const[e,i,n]=t.detail;this.notificationAction(e,i,n)}onNotificationClose(t){const[e,i]=t.detail;this.notificationClose(e,i)}}class N extends T{convertNotificationToNative(t){if(!n.Type.isStringFilled(t.getId())){throw new Error(`NotificationManager: You cannot send a notification without an ID.`)}const e=t.getUid();BXDesktopSystem.NotificationCreate(e);if(n.Type.isStringFilled(t.getTitle())){BXDesktopSystem.NotificationAddText(e,t.getTitle())}if(n.Type.isStringFilled(t.getText())){BXDesktopSystem.NotificationAddText(e,t.getText())}if(n.Type.isStringFilled(t.getIcon())){BXDesktopSystem.NotificationAddImage(e,t.getIcon())}if(t.getInputPlaceholderText()&&n.Type.isString(t.getInputPlaceholderText())){BXDesktopSystem.NotificationAddInput(e,t.getInputPlaceholderText(),p.USER_INPUT)}if(t.getButton1Text()&&n.Type.isStringFilled(t.getButton1Text())){BXDesktopSystem.NotificationAddAction(e,t.getButton1Text(),p.BUTTON_1)}if(t.getButton2Text()&&n.Type.isStringFilled(t.getButton2Text())){BXDesktopSystem.NotificationAddAction(e,n.Loc.getMessage("UI_NOTIFICATION_MANAGER_CLOSE"),p.BUTTON_2)}BXDesktopSystem.NotificationSetExpiration(e,h.NOTIFICATION_LIFETIME);return e}addTextToNotification(t,e){if(e.trim()===""){return}const i=44;if(e.length<=i){BXDesktopSystem.NotificationAddText(t,e);return}const n=" ";let o="";let s=e.split(n);while(s.length>0){if(o.length+s[0].length+1>i){break}o+=s.shift()+n}BXDesktopSystem.NotificationAddText(t,o);let r=s.join(n);if(r!==""){BXDesktopSystem.NotificationAddText(t,r)}}}class y extends T{convertNotificationToNative(t){if(!n.Type.isStringFilled(t.getId())){throw new Error(`NotificationManager: You cannot send a notification without an ID.`)}const e=t.getUid();BXDesktopSystem.NotificationCreate(e);if(n.Type.isStringFilled(t.getTitle())){BXDesktopSystem.NotificationAddText(e,t.getTitle())}if(n.Type.isStringFilled(t.getText())){BXDesktopSystem.NotificationAddText(e,t.getText())}if(n.Type.isStringFilled(t.getIcon())){BXDesktopSystem.NotificationAddImage(e,t.getIcon())}if(t.getInputPlaceholderText()&&n.Type.isString(t.getInputPlaceholderText())){BXDesktopSystem.NotificationAddInput(e,t.getInputPlaceholderText(),p.USER_INPUT)}if(t.getButton1Text()&&n.Type.isStringFilled(t.getButton1Text())){BXDesktopSystem.NotificationAddAction(e,t.getButton1Text(),p.BUTTON_1)}if(t.getButton2Text()&&n.Type.isStringFilled(t.getButton2Text())){BXDesktopSystem.NotificationAddAction(e,t.getButton2Text(),p.BUTTON_2)}BXDesktopSystem.NotificationSetExpiration(e,h.NOTIFICATION_LIFETIME);return e}}class x extends h{convertNotificationToNative(t){const e={title:t.getTitle()?t.getTitle():"",options:{body:"",tag:t.getUid(),renotify:true},onclick:e=>{e.preventDefault();window.focus();this.notificationClick(t.getUid())}};if(n.Type.isStringFilled(t.getIcon())){e.options.icon=t.getIcon()}if(n.Type.isStringFilled(t.getText())){e.options.body=t.getText()}return e}sendNotification(t){if(!u.isRunningOnAnyDevice()){return}u.checkRunningOnThisDevice().then((e=>{if(e){return}const i=new window.Notification(t.title,t.options);i.onclick=t.onclick}))}}class I extends o.UI.Notification.Action{constructor(t,e){super(t,e);this.setButtonClass(e.buttonType)}getContainer(){if(this.container!==null){return this.container}let t={text:this.getTitle()};if(n.Type.isFunction(this.events.click)){t.onclick=(t,e)=>{e.stopPropagation();this.events.click(t,e)}}const e=new s.Button(t);e.removeClass("ui-btn");e.addClass(I.BASE_BUTTON_CLASS);e.addClass(this.getButtonClass());this.container=e.getContainer();return this.container}static getButtonTypes(){return[I.TYPE_ACCEPT]}static isSupportedButtonType(t){return I.getButtonTypes().includes(t)}setButtonClass(t){this.buttonClass=I.isSupportedButtonType(t)?I.BASE_BUTTON_CLASS+"-"+t:""}getButtonClass(){return this.buttonClass}}I.BASE_BUTTON_CLASS="ui-notification-manager-browser-button";I.TYPE_ACCEPT="accept";let w=t=>t,B,m,C,S,A,v;class E extends o.UI.Notification.Balloon{constructor(t){super(t);this.userInputContainerNode=null;this.userInputNode=null}setActions(t){this.actions=[];if(n.Type.isArray(t)){t.forEach((t=>this.actions.push(new I(this,t))))}}getContainer(){if(this.container!==null){return this.container}const t=()=>this.handleMouseEnter();const e=()=>this.handleMouseLeave();this.container=n.Tag.render(B||(B=w`
			<div
				class="ui-notification-manager-browser-balloon"
				onmouseenter="${0}"
				onmouseleave="${0}"
			>
				${0}
			</div>
		`),t,e,this.render());return this.container}render(){this.animationClassName="ui-notification-manager-browser-balloon-animate";const t=n.Type.isNumber(this.getWidth())?this.getWidth()+"px":this.getWidth();return n.Tag.render(m||(m=w`
			<div
				class="ui-notification-manager-browser-content"
				style="width: ${0}"
			>
				<div
					class="ui-notification-manager-browser-message"
					onclick="${0}"
				>
					${0}
					<div class="ui-notification-manager-browser-column">
						${0}
						${0}
						${0}
						${0}
					</div>
				</div>
				${0}
			</div>
		`),t,this.handleContentClick.bind(this),this.getIconNode(),this.getTitleNode(),this.getTextNode(),this.getUserInputContainerNode(),this.getActionsNode(),this.getCloseButtonNode())}getTitleNode(){if(!n.Type.isStringFilled(this.getData().title)){return""}const t=n.Dom.create({tag:"span",attrs:{className:"ui-notification-manager-browser-title"},text:this.getData().title}).outerHTML;return n.Tag.render(C||(C=w`<div class="ui-notification-manager-browser-title">${0}<div>`),t)}getTextNode(){if(!n.Type.isStringFilled(this.getData().text)){return""}return n.Dom.create({tag:"div",attrs:{className:"ui-notification-manager-browser-text"},text:this.getData().text})}getIconNode(){if(!n.Type.isStringFilled(this.getData().icon)){return""}return n.Dom.create({tag:"div",className:"ui-notification-manager-browser-column",children:[n.Dom.create({tag:"img",style:{height:"44px",width:"44px"},attrs:{className:"ui-notification-manager-browser-icon",src:this.getData().icon}})]})}getActionsNode(){const t=this.getActions().map((t=>t.getContainer()));if(!n.Type.isArrayFilled(t)){return""}return n.Tag.render(S||(S=w`
			<div class="ui-notification-manager-browser-actions">
				${0}
			</div>
		`),t)}getUserInputContainerNode(){if(!n.Type.isString(this.getData().inputPlaceholderText)){return""}const t=t=>t.stopPropagation();const e=n.Text.encode(this.getId());const i=n.Text.encode(this.getData().inputPlaceholderText);return n.Tag.render(A||(A=w`
			<div class="ui-notification-manager-browser-actions">
				<div class="ui-notification-manager-browser-column ui-notification-manager-browser-column-wide">
					<div class="ui-notification-manager-browser-row">
						<button
							class="ui-notification-manager-browser-button"
							id="ui-notification-manager-browser-reply-toggle-${0}"
							onclick="${0}"
						>
							<span class="ui-btn-text">${0}</span>
						</button>
					</div>
					<div
						class="ui-notification-manager-browser-row ui-notification-manager-browser-row-reply"
						id="ui-notification-manager-browser-reply-container-${0}"
					>
						<div class="ui-notification-manager-browser-reply-wrapper">
							<input
								type="text"
								class="ui-notification-manager-browser-input-reply"
								placeholder="${0}"
								id="ui-notification-manager-browser-reply-${0}"
								onkeyup="${0}"
								onclick="${0}"
								disabled
							>
						</div>
						<div
							class="ui-notification-manager-browser-button-reply"
							onclick="${0}"
						/>
					</div>
				</div>
			</div>
		`),e,this.toggleUserInputContainerNode.bind(this),n.Loc.getMessage("UI_NOTIFICATION_MANAGER_REPLY"),e,i,e,this.handleUserInputEnter.bind(this),t,this.handleUserInputClick.bind(this))}toggleUserInputContainerNode(t){t.stopPropagation();const e=n.Text.encode(this.getId());if(!this.userInputContainerNode){this.userInputContainerNode=document.getElementById("ui-notification-manager-browser-reply-container-"+e)}if(!this.userInputNode){this.userInputNode=document.getElementById("ui-notification-manager-browser-reply-"+e)}if(!this.replyToggleButton){this.replyToggleButton=document.getElementById("ui-notification-manager-browser-reply-toggle-"+e)}this.showUserInput=!this.showUserInput;if(this.showUserInput){this.setAutoHide(false);this.deactivateAutoHide();this.replyToggleButton.style.display="none";this.userInputContainerNode.classList.add("ui-notification-manager-browser-row-reply-animate");this.userInputNode.disabled=false;this.userInputNode.focus()}else{this.setAutoHide(true);this.activateAutoHide();this.replyToggleButton.style.display="block";this.userInputContainerNode.classList.remove("ui-notification-manager-browser-row-reply-animate");this.userInputNode.disabled=true}}getCloseButtonNode(){if(!this.isCloseButtonVisible()){return""}return n.Tag.render(v||(v=w`
			<div
				class="ui-notification-manager-browser-button-close"
				onclick="${0}"
			/>
		`),this.handleCloseBtnClick.bind(this))}handleCloseBtnClick(t){t.stopPropagation();if(n.Type.isFunction(this.getData().closedByUserHandler)){this.getData().closedByUserHandler()}super.handleCloseBtnClick()}handleContentClick(){if(n.Type.isFunction(this.getData().clickHandler)){this.getData().clickHandler()}this.close()}handleUserInputEnter(t){if(!n.Type.isFunction(this.getData().userInputHandler)){return}const e=t.target.value;if(t.keyCode===E.KEY_CODE.ENTER&&e!==""){this.getData().userInputHandler(e);this.close();return}if(t.keyCode===E.KEY_CODE.ESC&&e===""){if(n.Type.isFunction(this.getData().closedByUserHandler)){this.getData().closedByUserHandler()}this.close()}}handleUserInputClick(t){t.stopPropagation();if(!n.Type.isFunction(this.getData().userInputHandler)){return}const e=this.userInputNode.value;if(e!==""){this.getData().userInputHandler(e);this.close()}}}E.KEY_CODE={ENTER:13,ESC:27};class b extends h{convertNotificationToNative(t){if(!n.Type.isStringFilled(t.getId())){throw new Error(`NotificationManager: You cannot send a notification without an ID.`)}const e=()=>{this.notificationClose(t.getUid(),f.CLOSED_BY_USER)};const i=()=>{this.notificationClick(t.getUid())};const o=e=>{this.notificationAction(t.getUid(),p.BUTTON_1,e)};const s={id:t.getUid(),category:t.getCategory(),type:E,data:{title:t.getTitle(),text:t.getText(),icon:t.getIcon(),closedByUserHandler:e,clickHandler:i,userInputHandler:o},actions:[],width:380,position:"top-right",autoHideDelay:6e3};if(t.getInputPlaceholderText()){s.data.inputPlaceholderText=t.getInputPlaceholderText();return s}const r=t.getButton1Text()&&n.Type.isStringFilled(t.getButton1Text());const a=t.getButton2Text()&&n.Type.isStringFilled(t.getButton2Text());if(r){const e={id:p.BUTTON_1,title:t.getButton1Text(),events:{click:(t,e,i)=>this.onNotificationAction(t,e,i)}};if(a){e.buttonType=I.TYPE_ACCEPT}s.actions.push(e)}if(a){const e={id:p.BUTTON_2,title:t.getButton2Text(),events:{click:(t,e,i)=>this.onNotificationAction(t,e,i)}};s.actions.push(e)}return s}sendNotification(t){o.UI.Notification.Center.notify(t)}onNotificationAction(t,e,i){e.close();this.notificationAction(e.id,i.id)}}class k{constructor(){this.provider=this.createProvider();e.PULL.subscribe(new d)}createProvider(){const t={eventNamespace:k.EVENT_NAMESPACE};if(u.isSupportedDesktopApp()&&u.isMac()){return new N(t)}if(u.isSupportedDesktopApp()&&u.isWindows()){return new y(t)}if(l.isSupportedBrowser()&&l.isNativeNotificationAllowed()){return new x(t)}return new b(t)}notify(t){const e=new a(t);this.sendNotification(e)}sendNotification(t){this.provider.notify(t)}subscribe(t,e){if(!g.isSupported(t)){throw new Error(`NotificationManager: event "${t}" is not supported.`)}this.provider.subscribe(t,e)}notifyViaDesktopProvider(t){if(u.isSupportedDesktopApp()&&u.isMac()){(new N).notify(t);return}if(u.isSupportedDesktopApp()&&u.isMac()){(new y).notify(t);return}throw new Error(`NotificationManager: unsupported environment for sending through a desktop provider.`)}}k.EVENT_NAMESPACE="BX.UI.NotificationManager";const U=new k;t.Notifier=U;t.Notification=a})(this.BX.UI.NotificationManager=this.BX.UI.NotificationManager||{},BX,BX.Event,BX,BX,BX.UI);
//# sourceMappingURL=notification-manager.bundle.map.js